package hunter20240515;

public class Person {
    private String name;
    private int age;

    public Person() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

//    public void keepPet(Dog dog, String something) {
//        System.out.println("年龄为" + this.age + "岁的" + this.name + "养了一只" + dog.getColor() + "颜色的" + dog.getAge() + "岁的狗");
//        dog.eat(something);
//    }
//
//    public void keepPet(Cat cat, String something) {
//        System.out.println("年龄为" + this.age + "岁的" + this.name + "养了一只" + cat.getColor() + "颜色的" + cat.getAge() + "岁的猫");
//        cat.eat(something);
//    }

    //利用多态的特性
    //一个方法，就能接收所有动物，包括猫和狗
    public void keepPet(Animal a, String something) {
        System.out.println("年龄为" + this.age + "岁的" + this.name + "养了一只" + a.getColor() + "颜色的" + a.getAge() + "岁的动物");
        a.eat(something);
    }
}
